(ns cl-slika.picture.pic
  (:use [clisk core functions patterns colours])
   (:import 
     [java.awt.image BufferedImage]
           [javax.imageio ImageIO])  )

;extenzija da se prosledi
(defn upisi-u-fajl
  [ sadrzaj ime-fajla]    
    (ImageIO/write sadrzaj "jpg" (clojure.java.io/file (str "./upload/" "-o-" ime-fajla )) 
  )
    )

(defn citanje [putanja] 
  ;try-catch za neuspesno citanje?
            (javax.imageio.ImageIO/read (java.io.File. (str putanja))) 
           )


(defn GrayFilter [] (com.jhlabs.image.GrayFilter.))
(defn GrayscaleFilter [] (com.jhlabs.image.GrayscaleFilter.))
(defn BlueFilter [] (com.jhlabs.image.MaskFilter. 0xff))
(defn GreenFilter [] (com.jhlabs.image.MaskFilter. 0xff00))
(defn RedFilter [] (com.jhlabs.image.MaskFilter. 0xff0000))
(defn ChromeFilter [] (com.jhlabs.image.ChromeFilter.))
(defn CrystallizeFilter [] (com.jhlabs.image.CrystallizeFilter.))
(defn BlurFilter [] (com.jhlabs.image.BlurFilter.))
(defn MarbleFilter [] (com.jhlabs.image.MarbleFilter.))
(defn KaleidoscopeFilter [] (com.jhlabs.image.KaleidoscopeFilter.))
(defn SolarizeFilter [] (com.jhlabs.image.SolarizeFilter.))
(defn QuantizeFilter [] (com.jhlabs.image.QuantizeFilter.))
(defn DiffusionFilter [] (com.jhlabs.image.DiffusionFilter.))
(defn HSBFilter [] (com.jhlabs.image.HSBAdjustFilter. 10 10 10 ))
;(defn ContrastFilter [] (com.jhlabs.image.ContrastFilter.  )) 
         ; ne moze lepo da se koristi posto clisk prima parametre samo u konstruktoru



(def niz-imena-filtera ["HSBFilter" "DiffusionFilter" "QuantizeFilter" "SolarizeFilter" "KaleidoscopeFilter" "MarbleFilter" "BlurFilter" "CrystallizeFilter" "ChromeFilter" "RedFilter" "GreenFilter" "BlueFilter" "GrayFilter" "GrayscaleFilter" ])

(defn uzas [slika-name f & par];slika f[index] par(ametar)
  
  (let 
    [file-path (str "./upload/" slika-name)
     src (citanje file-path)
        f1 (get niz-imena-filtera f)
        filter1 ((ns-resolve 'cl-slika.picture.pic (symbol  f1)));((resolve (symbol (str f))))
        slika3 (get (image-filter filter1 src ) :objects) ; image-filter vraca svasta
        ]
    
    (upisi-u-fajl (:value (bean (first slika3))) slika-name)
  
    )
  )
